package hivi.vn.hivigold.adapters;

import hivi.vn.hivigold.R;
import hivi.vn.hivigold.objects.Ct81;
import hivi.vn.hivigold.utils.Formats;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SelectDishAdapter extends BaseAdapter {
	ArrayList<Ct81> arr;
	Context context;

	public SelectDishAdapter(Context context, ArrayList<Ct81> arr) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.arr = arr;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arr == null ? 0 : arr.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arr == null ? null : arr.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View v = arg1;
		Holder h;
		if (v == null) {
			v = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.ct81row_layout, null);
			h = new Holder();
			h.tvMon = (TextView) v.findViewById(R.id.tvMon);
			h.tvSoluong = (TextView) v.findViewById(R.id.tvSoluong);
			h.tvGia = (TextView) v.findViewById(R.id.tvGia);
			h.tvCk = (TextView) v.findViewById(R.id.tvCk);
			h.tvTien = (TextView) v.findViewById(R.id.tvTien);
			v.setTag(h);
		} else {
			h = (Holder) v.getTag();
		}
		if (arr != null) {
			Ct81 g = arr.get(arg0);
			h.tvMon.setText(g.getVtName());
			h.tvSoluong.setText(Formats.number(g.getSo_luong()));
			h.tvGia.setText(Formats.money(g.getNguyen_gia()));
			h.tvCk.setText(Formats.percent(g.getCk()));
			h.tvTien.setText(Formats.money(g.getTien()));
		}
		return v;
	}

	public void swaper(ArrayList<Ct81> arr) {
		this.arr = arr;
		notifyDataSetChanged();
	}

	public Ct81 getCt81AtIndex(int index) {
		return arr.get(index);
	}

	static class Holder {
		TextView tvMon;
		TextView tvSoluong;
		TextView tvGia;
		TextView tvCk;
		TextView tvTien;
	}
}
